<?php

declare (strict_types=1);

namespace app\bbxw\controller;


use think\admin\Controller;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Shared\Date;
/**
 * 商品管理
 * @class Package
 * @package app\bbxw\controller
 */
class Goods extends Controller
{

    /**
     * 绑定数据表
     * @var string
     */
    private $table = 'goods';
    /**
     * 商品管理
     * @auth true
     * @menu true
     * @login true
     */
    public function index()
    {

        $this->title = '商品管理';
        $query = $this->_query($this->table);
        // 列表排序并显示
        $query->like('title')->order('sort asc')->page();

        $this->fetch();
    }

    /**
     * 图文列表数据处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    protected function _page_filter(array &$data)
    {
        foreach ($data as &$vo){
            if($vo['thumb']){
                $vo['thumb'] = explode('|',$vo['thumb'])[0];
            }
        }
    }


    /**
     * 添加套餐
     * @auth true
     */
    public function add()
    {
        $this->_form($this->table, 'form');
    }

    /**
     * 表单数据处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    protected function _form_filter(array &$data)
    {

    }
    /**
     * 编辑套餐
     * @auth true
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function edit()
    {
        $this->_form($this->table, 'form');
    }


    /**
     * 删除套餐
     * auth true
     */
    public function remove()
    {
        $this->_delete($this->table);
    }

    /**
     * 修改文章状态
     * @auth true
     * @throws \think\db\exception\DbException
     */
    public function state()
    {
        $this->_save($this->table, $this->_vali([
            'status.in:1,2'  => '状态值范围异常！',
            'status.require' => '状态值不能为空！',
        ]));
    }




}